import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render } from '@testing-library/react';
import Portal from './Portal';

test('should render the content into the specified DOM element', () => {
    const portalElement = document.createElement('div');
    render(
        <Portal portalElement={portalElement}>
            <p>Тестовый контент</p>
        </Portal>
    );

    expect(portalElement).toContainHTML('<p>Тестовый контент</p>');
});

test('should render the content into a DOM element with the specified id', () => {
    document.body.innerHTML = `
    <div id="portal-container"></div>
  `;

    render(
        <Portal portalId="portal-container">
            <p>Тестовый контент</p>
        </Portal>
    );

    expect(document.getElementById('portal-container')).toContainHTML('<p>Тестовый контент</p>');
});

test('should render content into the document body if no DOM element or id is specified', () => {
    render(
        <Portal>
            <p>Тестовый контент</p>
        </Portal>
    );

    expect(document.body).toContainHTML('<p>Тестовый контент</p>');
});